<?php

namespace app\common\model;

use think\Model;

class Classroom extends Model
{
    protected $connection = 'db2';

    // 表名
    protected $name = 'classroom';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = false;

    /**
     * @var array 教室类型
     */
    public static $typeList = [
        '1' => '行政教室',
        '2' => '走班教室',
        '3' => '公共教室',
    ];

    public function school()
    {
        return $this->belongsTo('School');
    }

    public function garden()
    {
        return $this->belongsTo('Garden', 'garden_id', 'id', [], 'LEFT')->field('id,name');
    }

    public function building()
    {
        return $this->belongsTo('Building');
    }

    public function getTypeTextAttr($value, $data)
    {
        return isset(self::$typeList[$data['type']]) ? self::$typeList[$data['type']] : '';
    }
}
